from rest_framework import serializers
from apps.goods.models import Goods
from jingxi_shop_project.settings import IMAGE_URL


class GoodsSerializer(serializers.ModelSerializer):
    # SerializerMethodField方法允许你为序列化器定义一个名为 get_属性 的方法，这个方法返回的值将作为该字段的值在序列化时输出
    photo_URL = serializers.SerializerMethodField()
    def get_photo_URL(self, obj):
        return IMAGE_URL + obj.photo_URL
    class Meta:
        model = Goods
        fields = "__all__"